package scales.xml.dsl
import scales.utils.{AsBoolean, booleanMatcher, booleanAndTMatcher}
import scales.xml.{
NoNamespaceQName, PrefixedQName, AttributeQName,
Attribute, XmlTree, Doc, XmlVersion, XmlCBF,
XmlPath, Elem, XCC, XmlItem, QName,
ScalesXml, Text, Namespace, <}
class QNameMatcher(qname : QName) {
import ScalesXml._
def unapply( elem : Elem ) : Option[Elem] = if (elem.name =:= qname) Some(elem) else None
def unapply( attrib : Attribute ) : Option[Attribute] = if (toQName(attrib.name) =:= qname) Some(attrib) else None
}
class QNameMPimper( qname : QName ) {
def m = new QNameMatcher(qname)
def matcher = m
}
class NamespaceMatcher(ns : Namespace) {
import ScalesXml._
def unapply( elem : Elem ) : Option[Elem] =
if (elem.name.namespace == ns) Some(elem) else None
def unapply( attrib : Attribute ) : Option[Attribute] =
if (toQName(attrib.name).namespace == ns) Some(attrib) else None
}
class NSMPimper( ns : Namespace ) {
def m = new NamespaceMatcher(ns)
def matcher = m
}
trait XPathMatcher {
def pathMatcher[T : AsBoolean]( pathEval : (XmlTree) => T ) = booleanMatcher[XmlTree, T](pathEval)
def pathAndTreeMatcher[T : AsBoolean]( pathEval : (XmlTree) => T ) = booleanAndTMatcher[XmlTree, T](pathEval)
}
<iframe src="https://scalesxml.github.io/scales-xml_2.10/0.5.0/api.sxr/scales/xml/dsl/Matchers.scala.html" width="1280" height="720" frameborder="0"> </iframe>